<?php
namespace app\beautiful\model\appointment;
use app\beautiful\model\project\ProjectModel;
use app\common\model\CommonModel;

class TechnicianProjectModel extends CommonModel{
    protected  $name = 'beautiful_technician_project';
    protected  $pk   = 'bind_id';

    public function project()
    {
        return $this->hasOne(ProjectModel::class,'project_id','project_id');
    }

    public function getEngagedNumSumByTechnicianId($technicianTds){
        $where = [
            ['technician_id','IN',$technicianTds],
        ];

        $datas = $this->field('technician_id,SUM(engaged_num) AS engaged_num')->where($where)->group('technician_id')->select();
        $return = [];
        foreach($datas as $val){
            $return[$val['technician_id']] = $val['engaged_num'];
        }
        return $return;
    }

    public function getEngagedNumSumByProjectId($projectIds){
        $where = [
            ['project_id','IN',$projectIds],
        ];

        $datas = $this->field('project_id,SUM(engaged_num) AS engaged_num')->where($where)->group('project_id')->select();
        $return = [];
        foreach($datas as $val){
            $return[$val['project_id']] = $val['engaged_num'];
        }
        return $return;
    }
}
